package livraria.util;

import java.text.*;
import java.util.Date;

public class ConverteData {

	public static String formatarData(String data) throws Exception
	{
		if(data == null || data.equals(""))
			return null;
		
		String dataF = null;
		
		try
		{
			DateFormat df = new SimpleDateFormat("yyyy");
			Date date = (Date) df.parse(data);
			dataF = df.format(date);
		}
		catch(ParseException e)
		{
			throw e;
		}
		
		return dataF;
		
	}
	
	
	public static Date formatarData(Date data) throws Exception
	{
		if(data == null)
			return null;
		
		Date date = null;
		date = new Date(data.getTime() );
		return date;
		
	}
	
	public static Date strToData(String data) throws Exception
	{
		if(data == null)
			return null;
		
		Date dataF = null;
		
		try
		{
			DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
			long timestamp = df.parse(data).getTime();
			dataF = new Date(timestamp);
		}
		catch(ParseException e)
		{
			throw e;
		}
		
		return dataF;
		
	}
	
}
